package com.example.swimfish;

import javafx.scene.media.*;

public class AudioManager {
    private MediaPlayer waterSound;
    private MediaPlayer fishSound;

    public AudioManager() {
        // 加载水声背景音
        Media waterMedia = new Media(getClass().getResource("/sounds/water.mp3").toString());
        waterSound = new MediaPlayer(waterMedia);
        waterSound.setCycleCount(MediaPlayer.INDEFINITE);
        waterSound.setVolume(0.3);

        // 加载鱼游动音效
        Media fishMedia = new Media(getClass().getResource("/sounds/fish_swim.mp3").toString());
        fishSound = new MediaPlayer(fishMedia);
        fishSound.setVolume(0.2);
    }

    public void playBackground() {
        waterSound.play();
    }

    public void playSwimSound() {
        if (fishSound.getStatus() != MediaPlayer.Status.PLAYING) {
            fishSound.stop();
            fishSound.play();
        }
    }

    public void stopAll() {
        waterSound.stop();
        fishSound.stop();
    }
}